package at.fhooe.mc.master.clc.server.domain.jdo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

import at.fhooe.mc.master.clc.server.domain.AbstractTestable;
import at.fhooe.mc.master.clc.server.domain.IBigEntity;
import at.fhooe.mc.master.clc.server.domain.IEmbeddedEntity;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class BigEntityJdo extends AbstractTestable implements IBigEntity
{
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	// needs to be Key because of embedded classes
    private Key id; // automatically populated by JDO
	
	 // each 100 entries
	@Persistent
	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true") // JDO extension-annotation for unindexed fields
	private List<String> stringList1;
	
	@Persistent
	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
	private Map<String, String> stringMap1;
	
	@Persistent
	@Embedded
	private EmbeddedJDOEntity embeddedEntity;
	// 10 entries
	
//	@Persistent(serialized = "true") // without serialized this is very limited and buggy!
//	@Extension(vendorName="datanucleus", key="gae.unindexed", value="true") 
//	private List<EmbeddedJDOListEntity> embeddedEntityList;
	
	public BigEntityJdo() {}
	 
	public BigEntityJdo(boolean generate)
	{
		if (generate)
		{
			stringMap1 = new HashMap<String, String>();
			stringList1 = new ArrayList<String>();
			
			for (int i = 0; i < 100; i++)
			{
				stringMap1.put("1_key" + i, "1_value" + i);
				stringList1.add("string_entry" + i);
			}
			
			embeddedEntity = new EmbeddedJDOEntity(true);
//			embeddedEntityList = new ArrayList<EmbeddedJDOListEntity>();
//			for (int i = 0; i < 10; i++)
//			{
//				embeddedEntityList.add(new EmbeddedJDOListEntity(true));
//			}
		}
	}
	
	@Override
	public Long getId()
	{
		return this.id.getId();
	}
	
	@Override
	public Map<String, String> getStringMap1()
	{
		return this.stringMap1;
	}

	@Override
	public IEmbeddedEntity getEmbeddedEntity()
	{
//		return null;
		return this.embeddedEntity;
	}

	@Override
	public List<? extends IEmbeddedEntity> getEmbeddedEntityList()
	{
		return null;
//		return this.embeddedEntityList;
	}

	@Override
	public List<String> getStringList1()
	{
		return this.stringList1;
	}

}
